$(function()
{	
	 var file = location.search.split('=')[2];
	 var user;
	/********************************************************************************************************************/
	$(':radio').click(function(){
		var ischecked = $(':radio').is(':checked');
		// alert('je suis la');
		if(ischecked == true)
		{
			var userName = $(this).val();
			user = userName;
			 $.post("./traitements/get_user_permissions.php",{_userName : userName ,_file : file },function(data)
			 {	
			    var obj = jQuery.parseJSON(data.toString().replace(';',''));
				if($.inArray("update",obj) > -1)
				{
					$('#updatechbx').attr('checked',true);
				}
				else
				{
					$('#updatechbx').attr('checked',false);
				}
				if($.inArray("read",obj) > -1)
				{
					$('#readchbx').attr('checked',true);
				}
				else
				{
					$('#readchbx').attr('checked',false);
				}
				if($.inArray("write",obj) > -1)
				{
					$('#writechbx').attr('checked',true);
				}
				else
				{
					$('#writechbx').attr('checked',false);
				}
				if($.inArray("delete",obj) > -1)
				{
					$('#deletechbx').attr('checked',true);
				}
				else
				{
					$('#deletechbx').attr('checked',false);
				}
			 });
		}
	});
	
	/********************************************************************************************************************/
	$(':checkbox').live('change', function()
	{
		var permission = $(this).val();
		if($(this).is(':checked'))
		{
			$.post("./traitements/modifier_droits.php",{_file : file,_permission : permission,_user : user },function()
			{
				//alert("ok");
			});
		}
		else
		{
			$.post("./traitements/deletePermission.php",{_file : file,_permission : permission,_user : user },function()
			{
				//alert("ok");
			});
		}
	});
	
});